package com.jar.exercise.算法.冒泡排序;

/**
 * @author ZhangShengHao
 * @className Demo1
 * @description TODO
 * @date 2020/1/29 21:53
 */
public class Demo {
	public static void main(String[] args) {
		int[] arr = new int[]{12, 32, 56, 89, 12, 32, -45, 0, 5};
		int[] maopao = maopao(arr);
		for (int i : maopao) {
			System.out.print(i + ",");
		}
	}

	private static int[] maopao(int[] arr) {
		for (int i = 0; i < arr.length - 1; i++) {
			for (int j = 0; j < arr.length - 1 - i; j++) {
				int flag;
				if (arr[j] > arr[j + 1]) {
					flag = arr[j];
					arr[j] = arr[j + 1];
					arr[j + 1] = flag;
				}
			}
		}
		return arr;
	}
}
